package cn.smartorigin.soas.frame;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import cn.smartorigin.soas.data.SqliteConnecter;
import cn.smartorigin.soas.data.TestData;
import cn.smartorigin.soas.frame.ModifyClient.BtnListener;
import cn.smartorigin.soas.frame.panel.ManagePlateTypePage;

public class ModifyPlateType  extends PopupDialogFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JButton mCfnBtn, mClrBtn;
	JTextField mClientName;
	String mClientNameStr;
	ManagePlateTypePage mtp;
	
	public ModifyPlateType(String cname, ManagePlateTypePage mt){
		super();
		this.mtp = mt;
		this.setTitle(" 镀种修改  - SOAS");	
		this.mClientNameStr = cname;

		this.compentInit();
	}
	
	private void compentInit(){
		this.setLayout(null);
		
		BtnListener btnlistener = new BtnListener();
		
		ImageIcon clrCfnIcon=new ImageIcon("res/images/modify.png");
		mCfnBtn = new JButton("确定", clrCfnIcon);
		mCfnBtn.setBounds(250,300,100,30);
		mCfnBtn.addActionListener(btnlistener);
		
		ImageIcon clrBtnIcon=new ImageIcon("img/ic_delete.png"); 
		mClrBtn = new JButton("取消",clrBtnIcon);
		mClrBtn.setBounds(450,300,100,30);
		mClrBtn.addActionListener(btnlistener);
		
		/**
		 * 客户名称
		 */
		JLabel clientName  = new JLabel("镀种名称：");
		clientName.setBounds(250,125,100,30);
		mClientName = new JTextField(mClientNameStr);
		mClientName.setBounds(350,125,200,30);
		mClientName.setBackground(Color.white);
		mClientName.addActionListener(btnlistener);
		
		this.add(mCfnBtn);
		this.add(mClrBtn);
		this.add(clientName);
		this.add(mClientName);
	}
	
	class BtnListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			Object  obj =(Object)e.getSource();
			if(obj == mCfnBtn){
				saveData();
				mtp.flashData();
				frameClose();
			}else if(obj == mClrBtn){
				frameClose();
			}
		}
	}
	
	private  void frameClose(){
		this.dispose();
	}
	
	private void saveData(){
		try {
			TestData.updatePlateType(new SqliteConnecter(), mClientName.getText(), mClientNameStr);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
